(bug 5167) Add {{SUBPAGENAME}} variable
[lhc/web/wiklou.git] / includes / Title.php
1 <?php
2 /**
3 * See title.txt
4 *
5 * @package MediaWiki
6 */
7
8 /** */
9 require_once( 'normal/UtfNormal.php' );
10
11 $wgTitleInterwikiCache = array();
12 $wgTitleCache = array();
13
14 define ( 'GAID_FOR_UPDATE', 1 );
15
16 # Title::newFromTitle maintains a cache to avoid
17 # expensive re-normalization of commonly used titles.
18 # On a batch operation this can become a memory leak
19 # if not bounded. After hitting this many titles,
20 # reset the cache.
21 define( 'MW_TITLECACHE_MAX', 1000 );
22
23 /**
24 * Title class
25 * - Represents a title, which may contain an interwiki designation or namespace
26 * - Can fetch various kinds of data from the database, albeit inefficiently.
27 *
28 * @package MediaWiki
29 */
30 class Title {
31 /**
32 * All member variables should be considered private
33 * Please use the accessor functions
34 */
35
36 /**#@+
37 * @access private
38 */
39
40 var $mTextform; # Text form (spaces not underscores) of the main part
41 var $mUrlform; # URL-encoded form of the main part
42 var $mDbkeyform; # Main part with underscores
43 var $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
44 var $mInterwiki; # Interwiki prefix (or null string)
45 var $mFragment; # Title fragment (i.e. the bit after the #)
46 var $mArticleID; # Article ID, fetched from the link cache on demand
47 var $mLatestID; # ID of most recent revision
48 var $mRestrictions; # Array of groups allowed to edit this article
49 # Only null or "sysop" are supported
50 var $mRestrictionsLoaded; # Boolean for initialisation on demand
51 var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
52 var $mDefaultNamespace; # Namespace index when there is no namespace
53 # Zero except in {{transclusion}} tags
54 var $mWatched; # Is $wgUser watching this page? NULL if unfilled, accessed through userIsWatching()
55 /**#@-*/
56
57
58 /**
59 * Constructor
60 * @access private
61 */
62 /* private */ function Title() {
63 $this->mInterwiki = $this->mUrlform =
64 $this->mTextform = $this->mDbkeyform = '';
65 $this->mArticleID = -1;
66 $this->mNamespace = NS_MAIN;
67 $this->mRestrictionsLoaded = false;
68 $this->mRestrictions = array();
69 # Dont change the following, NS_MAIN is hardcoded in several place
70 # See bug #696
71 $this->mDefaultNamespace = NS_MAIN;
72 $this->mWatched = NULL;
73 $this->mLatestID = false;
74 }
75
76 /**
77 * Create a new Title from a prefixed DB key
78 * @param string $key The database key, which has underscores
79 * instead of spaces, possibly including namespace and
80 * interwiki prefixes
81 * @return Title the new object, or NULL on an error
82 * @static
83 * @access public
84 */
85 /* static */ function newFromDBkey( $key ) {
86 $t = new Title();
87 $t->mDbkeyform = $key;
88 if( $t->secureAndSplit() )
89 return $t;
90 else
91 return NULL;
92 }
93
94 /**
95 * Create a new Title from text, such as what one would
96 * find in a link. Decodes any HTML entities in the text.
97 *
98 * @param string $text the link text; spaces, prefixes,
99 * and an initial ':' indicating the main namespace
100 * are accepted
101 * @param int $defaultNamespace the namespace to use if
102 * none is specified by a prefix
103 * @return Title the new object, or NULL on an error
104 * @static
105 * @access public
106 */
107 function newFromText( $text, $defaultNamespace = NS_MAIN ) {
108 global $wgTitleCache;
109 $fname = 'Title::newFromText';
110
111 if( is_object( $text ) ) {
112 wfDebugDieBacktrace( 'Title::newFromText given an object' );
113 }
114
115 /**
116 * Wiki pages often contain multiple links to the same page.
117 * Title normalization and parsing can become expensive on
118 * pages with many links, so we can save a little time by
119 * caching them.
120 *
121 * In theory these are value objects and won't get changed...
122 */
123 if( $defaultNamespace == NS_MAIN && isset( $wgTitleCache[$text] ) ) {
124 return $wgTitleCache[$text];
125 }
126
127 /**
128 * Convert things like &eacute; &#257; or &#x3017; into real text...
129 */
130 $filteredText = Sanitizer::decodeCharReferences( $text );
131
132 $t =& new Title();
133 $t->mDbkeyform = str_replace( ' ', '_', $filteredText );
134 $t->mDefaultNamespace = $defaultNamespace;
135
136 static $cachedcount = 0 ;
137 if( $t->secureAndSplit() ) {
138 if( $defaultNamespace == NS_MAIN ) {
139 if( $cachedcount >= MW_TITLECACHE_MAX ) {
140 # Avoid memory leaks on mass operations...
141 $wgTitleCache = array();
142 $cachedcount=0;
143 }
144 $cachedcount++;
145 $wgTitleCache[$text] =& $t;
146 }
147 return $t;
148 } else {
149 $ret = NULL;
150 return $ret;
151 }
152 }
153
154 /**
155 * Create a new Title from URL-encoded text. Ensures that
156 * the given title's length does not exceed the maximum.
157 * @param string $url the title, as might be taken from a URL
158 * @return Title the new object, or NULL on an error
159 * @static
160 * @access public
161 */
162 function newFromURL( $url ) {
163 global $wgLegalTitleChars;
164 $t = new Title();
165
166 # For compatibility with old buggy URLs. "+" is usually not valid in titles,
167 # but some URLs used it as a space replacement and they still come
168 # from some external search tools.
169 if ( strpos( $wgLegalTitleChars, '+' ) === false ) {
170 $url = str_replace( '+', ' ', $url );
171 }
172
173 $t->mDbkeyform = str_replace( ' ', '_', $url );
174 if( $t->secureAndSplit() ) {
175 return $t;
176 } else {
177 return NULL;
178 }
179 }
180
181 /**
182 * Create a new Title from an article ID
183 *
184 * @todo This is inefficiently implemented, the page row is requested
185 * but not used for anything else
186 *
187 * @param int $id the page_id corresponding to the Title to create
188 * @return Title the new object, or NULL on an error
189 * @access public
190 * @static
191 */
192 function newFromID( $id ) {
193 $fname = 'Title::newFromID';
194 $dbr =& wfGetDB( DB_SLAVE );
195 $row = $dbr->selectRow( 'page', array( 'page_namespace', 'page_title' ),
196 array( 'page_id' => $id ), $fname );
197 if ( $row !== false ) {
198 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
199 } else {
200 $title = NULL;
201 }
202 return $title;
203 }
204
205 /**
206 * Create a new Title from a namespace index and a DB key.
207 * It's assumed that $ns and $title are *valid*, for instance when
208 * they came directly from the database or a special page name.
209 * For convenience, spaces are converted to underscores so that
210 * eg user_text fields can be used directly.
211 *
212 * @param int $ns the namespace of the article
213 * @param string $title the unprefixed database key form
214 * @return Title the new object
215 * @static
216 * @access public
217 */
218 function &makeTitle( $ns, $title ) {
219 $t =& new Title();
220 $t->mInterwiki = '';
221 $t->mFragment = '';
222 $t->mNamespace = intval( $ns );
223 $t->mDbkeyform = str_replace( ' ', '_', $title );
224 $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
225 $t->mUrlform = wfUrlencode( $t->mDbkeyform );
226 $t->mTextform = str_replace( '_', ' ', $title );
227 return $t;
228 }
229
230 /**
231 * Create a new Title frrom a namespace index and a DB key.
232 * The parameters will be checked for validity, which is a bit slower
233 * than makeTitle() but safer for user-provided data.
234 *
235 * @param int $ns the namespace of the article
236 * @param string $title the database key form
237 * @return Title the new object, or NULL on an error
238 * @static
239 * @access public
240 */
241 function makeTitleSafe( $ns, $title ) {
242 $t = new Title();
243 $t->mDbkeyform = Title::makeName( $ns, $title );
244 if( $t->secureAndSplit() ) {
245 return $t;
246 } else {
247 return NULL;
248 }
249 }
250
251 /**
252 * Create a new Title for the Main Page
253 *
254 * @static
255 * @return Title the new object
256 * @access public
257 */
258 function newMainPage() {
259 return Title::newFromText( wfMsgForContent( 'mainpage' ) );
260 }
261
262 /**
263 * Create a new Title for a redirect
264 * @param string $text the redirect title text
265 * @return Title the new object, or NULL if the text is not a
266 * valid redirect
267 * @static
268 * @access public
269 */
270 function newFromRedirect( $text ) {
271 global $wgMwRedir;
272 $rt = NULL;
273 if ( $wgMwRedir->matchStart( $text ) ) {
274 if ( preg_match( '/\[{2}(.*?)(?:\||\]{2})/', $text, $m ) ) {
275 # categories are escaped using : for example one can enter:
276 # #REDIRECT [[:Category:Music]]. Need to remove it.
277 if ( substr($m[1],0,1) == ':') {
278 # We don't want to keep the ':'
279 $m[1] = substr( $m[1], 1 );
280 }
281
282 $rt = Title::newFromText( $m[1] );
283 # Disallow redirects to Special:Userlogout
284 if ( !is_null($rt) && $rt->getNamespace() == NS_SPECIAL && preg_match( '/^Userlogout/i', $rt->getText() ) ) {
285 $rt = NULL;
286 }
287 }
288 }
289 return $rt;
290 }
291
292 #----------------------------------------------------------------------------
293 # Static functions
294 #----------------------------------------------------------------------------
295
296 /**
297 * Get the prefixed DB key associated with an ID
298 * @param int $id the page_id of the article
299 * @return Title an object representing the article, or NULL
300 * if no such article was found
301 * @static
302 * @access public
303 */
304 function nameOf( $id ) {
305 $fname = 'Title::nameOf';
306 $dbr =& wfGetDB( DB_SLAVE );
307
308 $s = $dbr->selectRow( 'page', array( 'page_namespace','page_title' ), array( 'page_id' => $id ), $fname );
309 if ( $s === false ) { return NULL; }
310
311 $n = Title::makeName( $s->page_namespace, $s->page_title );
312 return $n;
313 }
314
315 /**
316 * Get a regex character class describing the legal characters in a link
317 * @return string the list of characters, not delimited
318 * @static
319 * @access public
320 */
321 function legalChars() {
322 global $wgLegalTitleChars;
323 return $wgLegalTitleChars;
324 }
325
326 /**
327 * Get a string representation of a title suitable for
328 * including in a search index
329 *
330 * @param int $ns a namespace index
331 * @param string $title text-form main part
332 * @return string a stripped-down title string ready for the
333 * search index
334 */
335 /* static */ function indexTitle( $ns, $title ) {
336 global $wgContLang;
337 require_once( 'SearchEngine.php' );
338
339 $lc = SearchEngine::legalSearchChars() . '&#;';
340 $t = $wgContLang->stripForSearch( $title );
341 $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
342 $t = strtolower( $t );
343
344 # Handle 's, s'
345 $t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
346 $t = preg_replace( "/([{$lc}]+)s'( |$)/", "\\1s ", $t );
347
348 $t = preg_replace( "/\\s+/", ' ', $t );
349
350 if ( $ns == NS_IMAGE ) {
351 $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
352 }
353 return trim( $t );
354 }
355
356 /*
357 * Make a prefixed DB key from a DB key and a namespace index
358 * @param int $ns numerical representation of the namespace
359 * @param string $title the DB key form the title
360 * @return string the prefixed form of the title
361 */
362 /* static */ function makeName( $ns, $title ) {
363 global $wgContLang;
364
365 $n = $wgContLang->getNsText( $ns );
366 return $n == '' ? $title : "$n:$title";
367 }
368
369 /**
370 * Returns the URL associated with an interwiki prefix
371 * @param string $key the interwiki prefix (e.g. "MeatBall")
372 * @return the associated URL, containing "$1", which should be
373 * replaced by an article title
374 * @static (arguably)
375 * @access public
376 */
377 function getInterwikiLink( $key ) {
378 global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgTitleInterwikiCache;
379 global $wgInterwikiCache;
380 $fname = 'Title::getInterwikiLink';
381
382 $key = strtolower( $key );
383
384 $k = $wgDBname.':interwiki:'.$key;
385 if( array_key_exists( $k, $wgTitleInterwikiCache ) ) {
386 return $wgTitleInterwikiCache[$k]->iw_url;
387 }
388
389 if ($wgInterwikiCache) {
390 return Title::getInterwikiCached( $key );
391 }
392
393 $s = $wgMemc->get( $k );
394 # Ignore old keys with no iw_local
395 if( $s && isset( $s->iw_local ) && isset($s->iw_trans)) {
396 $wgTitleInterwikiCache[$k] = $s;
397 return $s->iw_url;
398 }
399
400 $dbr =& wfGetDB( DB_SLAVE );
401 $res = $dbr->select( 'interwiki',
402 array( 'iw_url', 'iw_local', 'iw_trans' ),
403 array( 'iw_prefix' => $key ), $fname );
404 if( !$res ) {
405 return '';
406 }
407
408 $s = $dbr->fetchObject( $res );
409 if( !$s ) {
410 # Cache non-existence: create a blank object and save it to memcached
411 $s = (object)false;
412 $s->iw_url = '';
413 $s->iw_local = 0;
414 $s->iw_trans = 0;
415 }
416 $wgMemc->set( $k, $s, $wgInterwikiExpiry );
417 $wgTitleInterwikiCache[$k] = $s;
418
419 return $s->iw_url;
420 }
421
422 /**
423 * Fetch interwiki prefix data from local cache in constant database
424 *
425 * More logic is explained in DefaultSettings
426 *
427 * @return string URL of interwiki site
428 * @access public
429 */
430 function getInterwikiCached( $key ) {
431 global $wgDBname, $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
432 global $wgTitleInterwikiCache;
433 static $db, $site;
434
435 if (!$db)
436 $db=dba_open($wgInterwikiCache,'r','cdb');
437 /* Resolve site name */
438 if ($wgInterwikiScopes>=3 and !$site) {
439 $site = dba_fetch("__sites:{$wgDBname}", $db);
440 if ($site=="")
441 $site = $wgInterwikiFallbackSite;
442 }
443 $value = dba_fetch("{$wgDBname}:{$key}", $db);
444 if ($value=='' and $wgInterwikiScopes>=3) {
445 /* try site-level */
446 $value = dba_fetch("_{$site}:{$key}", $db);
447 }
448 if ($value=='' and $wgInterwikiScopes>=2) {
449 /* try globals */
450 $value = dba_fetch("__global:{$key}", $db);
451 }
452 if ($value=='undef')
453 $value='';
454 $s = (object)false;
455 $s->iw_url = '';
456 $s->iw_local = 0;
457 $s->iw_trans = 0;
458 if ($value!='') {
459 list($local,$url)=explode(' ',$value,2);
460 $s->iw_url=$url;
461 $s->iw_local=(int)$local;
462 }
463 $wgTitleInterwikiCache[$wgDBname.':interwiki:'.$key] = $s;
464 return $s->iw_url;
465 }
466 /**
467 * Determine whether the object refers to a page within
468 * this project.
469 *
470 * @return bool TRUE if this is an in-project interwiki link
471 * or a wikilink, FALSE otherwise
472 * @access public
473 */
474 function isLocal() {
475 global $wgTitleInterwikiCache, $wgDBname;
476
477 if ( $this->mInterwiki != '' ) {
478 # Make sure key is loaded into cache
479 $this->getInterwikiLink( $this->mInterwiki );
480 $k = $wgDBname.':interwiki:' . $this->mInterwiki;
481 return (bool)($wgTitleInterwikiCache[$k]->iw_local);
482 } else {
483 return true;
484 }
485 }
486
487 /**
488 * Determine whether the object refers to a page within
489 * this project and is transcludable.
490 *
491 * @return bool TRUE if this is transcludable
492 * @access public
493 */
494 function isTrans() {
495 global $wgTitleInterwikiCache, $wgDBname;
496
497 if ($this->mInterwiki == '')
498 return false;
499 # Make sure key is loaded into cache
500 $this->getInterwikiLink( $this->mInterwiki );
501 $k = $wgDBname.':interwiki:' . $this->mInterwiki;
502 return (bool)($wgTitleInterwikiCache[$k]->iw_trans);
503 }
504
505 /**
506 * Update the page_touched field for an array of title objects
507 * @todo Inefficient unless the IDs are already loaded into the
508 * link cache
509 * @param array $titles an array of Title objects to be touched
510 * @param string $timestamp the timestamp to use instead of the
511 * default current time
512 * @static
513 * @access public
514 */
515 function touchArray( $titles, $timestamp = '' ) {
516
517 if ( count( $titles ) == 0 ) {
518 return;
519 }
520 $dbw =& wfGetDB( DB_MASTER );
521 if ( $timestamp == '' ) {
522 $timestamp = $dbw->timestamp();
523 }
524 /*
525 $page = $dbw->tableName( 'page' );
526 $sql = "UPDATE $page SET page_touched='{$timestamp}' WHERE page_id IN (";
527 $first = true;
528
529 foreach ( $titles as $title ) {
530 if ( $wgUseFileCache ) {
531 $cm = new CacheManager($title);
532 @unlink($cm->fileCacheName());
533 }
534
535 if ( ! $first ) {
536 $sql .= ',';
537 }
538 $first = false;
539 $sql .= $title->getArticleID();
540 }
541 $sql .= ')';
542 if ( ! $first ) {
543 $dbw->query( $sql, 'Title::touchArray' );
544 }
545 */
546 // hack hack hack -- brion 2005-07-11. this was unfriendly to db.
547 // do them in small chunks:
548 $fname = 'Title::touchArray';
549 foreach( $titles as $title ) {
550 $dbw->update( 'page',
551 array( 'page_touched' => $timestamp ),
552 array(
553 'page_namespace' => $title->getNamespace(),
554 'page_title' => $title->getDBkey() ),
555 $fname );
556 }
557 }
558
559 #----------------------------------------------------------------------------
560 # Other stuff
561 #----------------------------------------------------------------------------
562
563 /** Simple accessors */
564 /**
565 * Get the text form (spaces not underscores) of the main part
566 * @return string
567 * @access public
568 */
569 function getText() { return $this->mTextform; }
570 /**
571 * Get the URL-encoded form of the main part
572 * @return string
573 * @access public
574 */
575 function getPartialURL() { return $this->mUrlform; }
576 /**
577 * Get the main part with underscores
578 * @return string
579 * @access public
580 */
581 function getDBkey() { return $this->mDbkeyform; }
582 /**
583 * Get the namespace index, i.e. one of the NS_xxxx constants
584 * @return int
585 * @access public
586 */
587 function getNamespace() { return $this->mNamespace; }
588 /**
589 * Get the namespace text
590 * @return string
591 * @access public
592 */
593 function getNsText() {
594 global $wgContLang;
595 return $wgContLang->getNsText( $this->mNamespace );
596 }
597 /**
598 * Get the namespace text of the subject (rather than talk) page
599 * @return string
600 * @access public
601 */
602 function getSubjectNsText() {
603 global $wgContLang;
604 return $wgContLang->getNsText( Namespace::getSubject( $this->mNamespace ) );
605 }
606
607 /**
608 * Get the interwiki prefix (or null string)
609 * @return string
610 * @access public
611 */
612 function getInterwiki() { return $this->mInterwiki; }
613 /**
614 * Get the Title fragment (i.e. the bit after the #)
615 * @return string
616 * @access public
617 */
618 function getFragment() { return $this->mFragment; }
619 /**
620 * Get the default namespace index, for when there is no namespace
621 * @return int
622 * @access public
623 */
624 function getDefaultNamespace() { return $this->mDefaultNamespace; }
625
626 /**
627 * Get title for search index
628 * @return string a stripped-down title string ready for the
629 * search index
630 */
631 function getIndexTitle() {
632 return Title::indexTitle( $this->mNamespace, $this->mTextform );
633 }
634
635 /**
636 * Get the prefixed database key form
637 * @return string the prefixed title, with underscores and
638 * any interwiki and namespace prefixes
639 * @access public
640 */
641 function getPrefixedDBkey() {
642 $s = $this->prefix( $this->mDbkeyform );
643 $s = str_replace( ' ', '_', $s );
644 return $s;
645 }
646
647 /**
648 * Get the prefixed title with spaces.
649 * This is the form usually used for display
650 * @return string the prefixed title, with spaces
651 * @access public
652 */
653 function getPrefixedText() {
654 global $wgContLang;
655 if ( empty( $this->mPrefixedText ) ) { // FIXME: bad usage of empty() ?
656 $s = $this->prefix( $this->mTextform );
657 $s = str_replace( '_', ' ', $s );
658 $this->mPrefixedText = $s;
659 }
660 return $this->mPrefixedText;
661 }
662
663 /**
664 * Get the prefixed title with spaces, plus any fragment
665 * (part beginning with '#')
666 * @return string the prefixed title, with spaces and
667 * the fragment, including '#'
668 * @access public
669 */
670 function getFullText() {
671 global $wgContLang;
672 $text = $this->getPrefixedText();
673 if( '' != $this->mFragment ) {
674 $text .= '#' . $this->mFragment;
675 }
676 return $text;
677 }
678
679 /**
680 * Get the lowest-level subpage name, i.e. the rightmost part after /
681 * @return string Subpage name
682 */
683 function getSubpageText() {
684 global $wgNamespacesWithSubpages;
685 if( $wgNamespacesWithSubpages[ $this->mNamespace ] ) {
686 $parts = explode( '/', $this->mTextform );
687 return( $parts[ count( $parts ) - 1 ] );
688 } else {
689 return( $this->mTextform );
690 }
691 }
692
693 /**
694 * Get a URL-encoded title (not an actual URL) including interwiki
695 * @return string the URL-encoded form
696 * @access public
697 */
698 function getPrefixedURL() {
699 $s = $this->prefix( $this->mDbkeyform );
700 $s = str_replace( ' ', '_', $s );
701
702 $s = wfUrlencode ( $s ) ;
703
704 # Cleaning up URL to make it look nice -- is this safe?
705 $s = str_replace( '%28', '(', $s );
706 $s = str_replace( '%29', ')', $s );
707
708 return $s;
709 }
710
711 /**
712 * Get a real URL referring to this title, with interwiki link and
713 * fragment
714 *
715 * @param string $query an optional query string, not used
716 * for interwiki links
717 * @return string the URL
718 * @access public
719 */
720 function getFullURL( $query = '' ) {
721 global $wgContLang, $wgServer, $wgRequest;
722
723 if ( '' == $this->mInterwiki ) {
724 $url = $this->getLocalUrl( $query );
725
726 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
727 // Correct fix would be to move the prepending elsewhere.
728 if ($wgRequest->getVal('action') != 'render') {
729 $url = $wgServer . $url;
730 }
731 } else {
732 $baseUrl = $this->getInterwikiLink( $this->mInterwiki );
733
734 $namespace = $wgContLang->getNsText( $this->mNamespace );
735 if ( '' != $namespace ) {
736 # Can this actually happen? Interwikis shouldn't be parsed.
737 $namespace .= ':';
738 }
739 $url = str_replace( '$1', $namespace . $this->mUrlform, $baseUrl );
740 if( $query != '' ) {
741 if( false === strpos( $url, '?' ) ) {
742 $url .= '?';
743 } else {
744 $url .= '&';
745 }
746 $url .= $query;
747 }
748 if ( '' != $this->mFragment ) {
749 $url .= '#' . $this->mFragment;
750 }
751 }
752 wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) );
753 return $url;
754 }
755
756 /**
757 * Get a URL with no fragment or server name. If this page is generated
758 * with action=render, $wgServer is prepended.
759 * @param string $query an optional query string; if not specified,
760 * $wgArticlePath will be used.
761 * @return string the URL
762 * @access public
763 */
764 function getLocalURL( $query = '' ) {
765 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
766
767 if ( $this->isExternal() ) {
768 $url = $this->getFullURL();
769 if ( $query ) {
770 // This is currently only used for edit section links in the
771 // context of interwiki transclusion. In theory we should
772 // append the query to the end of any existing query string,
773 // but interwiki transclusion is already broken in that case.
774 $url .= "?$query";
775 }
776 } else {
777 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
778 if ( $query == '' ) {
779 $url = str_replace( '$1', $dbkey, $wgArticlePath );
780 } else {
781 global $wgActionPaths;
782 $url = false;
783 if( !empty( $wgActionPaths ) &&
784 preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) )
785 {
786 $action = urldecode( $matches[2] );
787 if( isset( $wgActionPaths[$action] ) ) {
788 $query = $matches[1];
789 if( isset( $matches[4] ) ) $query .= $matches[4];
790 $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
791 if( $query != '' ) $url .= '?' . $query;
792 }
793 }
794 if ( $url === false ) {
795 if ( $query == '-' ) {
796 $query = '';
797 }
798 $url = "{$wgScript}?title={$dbkey}&{$query}";
799 }
800 }
801
802 // FIXME: this causes breakage in various places when we
803 // actually expected a local URL and end up with dupe prefixes.
804 if ($wgRequest->getVal('action') == 'render') {
805 $url = $wgServer . $url;
806 }
807 }
808 wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query ) );
809 return $url;
810 }
811
812 /**
813 * Get an HTML-escaped version of the URL form, suitable for
814 * using in a link, without a server name or fragment
815 * @param string $query an optional query string
816 * @return string the URL
817 * @access public
818 */
819 function escapeLocalURL( $query = '' ) {
820 return htmlspecialchars( $this->getLocalURL( $query ) );
821 }
822
823 /**
824 * Get an HTML-escaped version of the URL form, suitable for
825 * using in a link, including the server name and fragment
826 *
827 * @return string the URL
828 * @param string $query an optional query string
829 * @access public
830 */
831 function escapeFullURL( $query = '' ) {
832 return htmlspecialchars( $this->getFullURL( $query ) );
833 }
834
835 /**
836 * Get the URL form for an internal link.
837 * - Used in various Squid-related code, in case we have a different
838 * internal hostname for the server from the exposed one.
839 *
840 * @param string $query an optional query string
841 * @return string the URL
842 * @access public
843 */
844 function getInternalURL( $query = '' ) {
845 global $wgInternalServer;
846 $url = $wgInternalServer . $this->getLocalURL( $query );
847 wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
848 return $url;
849 }
850
851 /**
852 * Get the edit URL for this Title
853 * @return string the URL, or a null string if this is an
854 * interwiki link
855 * @access public
856 */
857 function getEditURL() {
858 global $wgServer, $wgScript;
859
860 if ( '' != $this->mInterwiki ) { return ''; }
861 $s = $this->getLocalURL( 'action=edit' );
862
863 return $s;
864 }
865
866 /**
867 * Get the HTML-escaped displayable text form.
868 * Used for the title field in <a> tags.
869 * @return string the text, including any prefixes
870 * @access public
871 */
872 function getEscapedText() {
873 return htmlspecialchars( $this->getPrefixedText() );
874 }
875
876 /**
877 * Is this Title interwiki?
878 * @return boolean
879 * @access public
880 */
881 function isExternal() { return ( '' != $this->mInterwiki ); }
882
883 /**
884 * Is this page "semi-protected" - the *only* protection is autoconfirm?
885 *
886 * @param string Action to check (default: edit)
887 * @return bool
888 */
889 function isSemiProtected( $action = 'edit' ) {
890 $restrictions = $this->getRestrictions( $action );
891 # We do a full compare because this could be an array
892 foreach( $restrictions as $restriction ) {
893 if( strtolower( $restriction ) != 'autoconfirmed' ) {
894 return( false );
895 }
896 }
897 return( true );
898 }
899
900 /**
901 * Does the title correspond to a protected article?
902 * @param string $what the action the page is protected from,
903 * by default checks move and edit
904 * @return boolean
905 * @access public
906 */
907 function isProtected( $action = '' ) {
908 global $wgRestrictionLevels;
909 if ( -1 == $this->mNamespace ) { return true; }
910
911 if( $action == 'edit' || $action == '' ) {
912 $r = $this->getRestrictions( 'edit' );
913 foreach( $wgRestrictionLevels as $level ) {
914 if( in_array( $level, $r ) && $level != '' ) {
915 return( true );
916 }
917 }
918 }
919
920 if( $action == 'move' || $action == '' ) {
921 $r = $this->getRestrictions( 'move' );
922 foreach( $wgRestrictionLevels as $level ) {
923 if( in_array( $level, $r ) && $level != '' ) {
924 return( true );
925 }
926 }
927 }
928
929 return false;
930 }
931
932 /**
933 * Is $wgUser is watching this page?
934 * @return boolean
935 * @access public
936 */
937 function userIsWatching() {
938 global $wgUser;
939
940 if ( is_null( $this->mWatched ) ) {
941 if ( -1 == $this->mNamespace || 0 == $wgUser->getID()) {
942 $this->mWatched = false;
943 } else {
944 $this->mWatched = $wgUser->isWatched( $this );
945 }
946 }
947 return $this->mWatched;
948 }
949
950 /**
951 * Can $wgUser perform $action this page?
952 * @param string $action action that permission needs to be checked for
953 * @return boolean
954 * @access private
955 */
956 function userCan($action) {
957 $fname = 'Title::userCan';
958 wfProfileIn( $fname );
959
960 global $wgUser;
961
962 $result = true;
963 if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) ) ) {
964 wfProfileOut( $fname );
965 return $result;
966 }
967
968 if( NS_SPECIAL == $this->mNamespace ) {
969 wfProfileOut( $fname );
970 return false;
971 }
972 // XXX: This is the code that prevents unprotecting a page in NS_MEDIAWIKI
973 // from taking effect -ævar
974 if( NS_MEDIAWIKI == $this->mNamespace &&
975 !$wgUser->isAllowed('editinterface') ) {
976 wfProfileOut( $fname );
977 return false;
978 }
979
980 if( $this->mDbkeyform == '_' ) {
981 # FIXME: Is this necessary? Shouldn't be allowed anyway...
982 wfProfileOut( $fname );
983 return false;
984 }
985
986 # protect global styles and js
987 if ( NS_MEDIAWIKI == $this->mNamespace
988 && preg_match("/\\.(css|js)$/", $this->mTextform )
989 && !$wgUser->isAllowed('editinterface') ) {
990 wfProfileOut( $fname );
991 return false;
992 }
993
994 # protect css/js subpages of user pages
995 # XXX: this might be better using restrictions
996 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
997 if( NS_USER == $this->mNamespace
998 && preg_match("/\\.(css|js)$/", $this->mTextform )
999 && !$wgUser->isAllowed('editinterface')
1000 && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) ) {
1001 wfProfileOut( $fname );
1002 return false;
1003 }
1004
1005 foreach( $this->getRestrictions($action) as $right ) {
1006 // Backwards compatibility, rewrite sysop -> protect
1007 if ( $right == 'sysop' ) {
1008 $right = 'protect';
1009 }
1010 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1011 wfProfileOut( $fname );
1012 return false;
1013 }
1014 }
1015
1016 if( $action == 'move' &&
1017 !( $this->isMovable() && $wgUser->isAllowed( 'move' ) ) ) {
1018 wfProfileOut( $fname );
1019 return false;
1020 }
1021
1022 if( $action == 'create' ) {
1023 if( ( $this->isTalkPage() && !$wgUser->isAllowed( 'createtalk' ) ) ||
1024 ( !$this->isTalkPage() && !$wgUser->isAllowed( 'createpage' ) ) ) {
1025 return false;
1026 }
1027 }
1028
1029 wfProfileOut( $fname );
1030 return true;
1031 }
1032
1033 /**
1034 * Can $wgUser edit this page?
1035 * @return boolean
1036 * @access public
1037 */
1038 function userCanEdit() {
1039 return $this->userCan('edit');
1040 }
1041
1042 /**
1043 * Can $wgUser move this page?
1044 * @return boolean
1045 * @access public
1046 */
1047 function userCanMove() {
1048 return $this->userCan('move');
1049 }
1050
1051 /**
1052 * Would anybody with sufficient privileges be able to move this page?
1053 * Some pages just aren't movable.
1054 *
1055 * @return boolean
1056 * @access public
1057 */
1058 function isMovable() {
1059 return Namespace::isMovable( $this->getNamespace() )
1060 && $this->getInterwiki() == '';
1061 }
1062
1063 /**
1064 * Can $wgUser read this page?
1065 * @return boolean
1066 * @access public
1067 */
1068 function userCanRead() {
1069 global $wgUser;
1070
1071 $result = true;
1072 if ( !wfRunHooks( 'userCan', array( &$this, &$wgUser, "read", &$result ) ) ) {
1073 return $result;
1074 }
1075
1076 if( $wgUser->isAllowed('read') ) {
1077 return true;
1078 } else {
1079 global $wgWhitelistRead;
1080
1081 /** If anon users can create an account,
1082 they need to reach the login page first! */
1083 if( $wgUser->isAllowed( 'createaccount' )
1084 && $this->getNamespace() == NS_SPECIAL
1085 && $this->getText() == 'Userlogin' ) {
1086 return true;
1087 }
1088
1089 /** some pages are explicitly allowed */
1090 $name = $this->getPrefixedText();
1091 if( $wgWhitelistRead && in_array( $name, $wgWhitelistRead ) ) {
1092 return true;
1093 }
1094
1095 # Compatibility with old settings
1096 if( $wgWhitelistRead && $this->getNamespace() == NS_MAIN ) {
1097 if( in_array( ':' . $name, $wgWhitelistRead ) ) {
1098 return true;
1099 }
1100 }
1101 }
1102 return false;
1103 }
1104
1105 /**
1106 * Is this a talk page of some sort?
1107 * @return bool
1108 * @access public
1109 */
1110 function isTalkPage() {
1111 return Namespace::isTalk( $this->getNamespace() );
1112 }
1113
1114 /**
1115 * Is this a .css or .js subpage of a user page?
1116 * @return bool
1117 * @access public
1118 */
1119 function isCssJsSubpage() {
1120 return ( NS_USER == $this->mNamespace and preg_match("/\\.(css|js)$/", $this->mTextform ) );
1121 }
1122 /**
1123 * Is this a *valid* .css or .js subpage of a user page?
1124 * Check that the corresponding skin exists
1125 */
1126 function isValidCssJsSubpage() {
1127 global $wgValidSkinNames;
1128 return( $this->isCssJsSubpage() && array_key_exists( $this->getSkinFromCssJsSubpage(), $wgValidSkinNames ) );
1129 }
1130 /**
1131 * Trim down a .css or .js subpage title to get the corresponding skin name
1132 */
1133 function getSkinFromCssJsSubpage() {
1134 $subpage = explode( '/', $this->mTextform );
1135 $subpage = $subpage[ count( $subpage ) - 1 ];
1136 return( str_replace( array( '.css', '.js' ), array( '', '' ), $subpage ) );
1137 }
1138 /**
1139 * Is this a .css subpage of a user page?
1140 * @return bool
1141 * @access public
1142 */
1143 function isCssSubpage() {
1144 return ( NS_USER == $this->mNamespace and preg_match("/\\.css$/", $this->mTextform ) );
1145 }
1146 /**
1147 * Is this a .js subpage of a user page?
1148 * @return bool
1149 * @access public
1150 */
1151 function isJsSubpage() {
1152 return ( NS_USER == $this->mNamespace and preg_match("/\\.js$/", $this->mTextform ) );
1153 }
1154 /**
1155 * Protect css/js subpages of user pages: can $wgUser edit
1156 * this page?
1157 *
1158 * @return boolean
1159 * @todo XXX: this might be better using restrictions
1160 * @access public
1161 */
1162 function userCanEditCssJsSubpage() {
1163 global $wgUser;
1164 return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) );
1165 }
1166
1167 /**
1168 * Loads a string into mRestrictions array
1169 * @param string $res restrictions in string format
1170 * @access public
1171 */
1172 function loadRestrictions( $res ) {
1173 foreach( explode( ':', trim( $res ) ) as $restrict ) {
1174 $temp = explode( '=', trim( $restrict ) );
1175 if(count($temp) == 1) {
1176 // old format should be treated as edit/move restriction
1177 $this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) );
1178 $this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) );
1179 } else {
1180 $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );
1181 }
1182 }
1183 $this->mRestrictionsLoaded = true;
1184 }
1185
1186 /**
1187 * Accessor/initialisation for mRestrictions
1188 * @param string $action action that permission needs to be checked for
1189 * @return array the array of groups allowed to edit this article
1190 * @access public
1191 */
1192 function getRestrictions($action) {
1193 $id = $this->getArticleID();
1194 if ( 0 == $id ) { return array(); }
1195
1196 if ( ! $this->mRestrictionsLoaded ) {
1197 $dbr =& wfGetDB( DB_SLAVE );
1198 $res = $dbr->selectField( 'page', 'page_restrictions', 'page_id='.$id );
1199 $this->loadRestrictions( $res );
1200 }
1201 if( isset( $this->mRestrictions[$action] ) ) {
1202 return $this->mRestrictions[$action];
1203 }
1204 return array();
1205 }
1206
1207 /**
1208 * Is there a version of this page in the deletion archive?
1209 * @return int the number of archived revisions
1210 * @access public
1211 */
1212 function isDeleted() {
1213 $fname = 'Title::isDeleted';
1214 if ( $this->getNamespace() < 0 ) {
1215 $n = 0;
1216 } else {
1217 $dbr =& wfGetDB( DB_SLAVE );
1218 $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
1219 'ar_title' => $this->getDBkey() ), $fname );
1220 }
1221 return (int)$n;
1222 }
1223
1224 /**
1225 * Get the article ID for this Title from the link cache,
1226 * adding it if necessary
1227 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select
1228 * for update
1229 * @return int the ID
1230 * @access public
1231 */
1232 function getArticleID( $flags = 0 ) {
1233 $linkCache =& LinkCache::singleton();
1234 if ( $flags & GAID_FOR_UPDATE ) {
1235 $oldUpdate = $linkCache->forUpdate( true );
1236 $this->mArticleID = $linkCache->addLinkObj( $this );
1237 $linkCache->forUpdate( $oldUpdate );
1238 } else {
1239 if ( -1 == $this->mArticleID ) {
1240 $this->mArticleID = $linkCache->addLinkObj( $this );
1241 }
1242 }
1243 return $this->mArticleID;
1244 }
1245
1246 function getLatestRevID() {
1247 if ($this->mLatestID !== false)
1248 return $this->mLatestID;
1249
1250 $db =& wfGetDB(DB_SLAVE);
1251 return $this->mLatestID = $db->selectField( 'revision',
1252 "max(rev_id)",
1253 array('rev_page' => $this->getArticleID()),
1254 'Title::getLatestRevID' );
1255 }
1256
1257 /**
1258 * This clears some fields in this object, and clears any associated
1259 * keys in the "bad links" section of the link cache.
1260 *
1261 * - This is called from Article::insertNewArticle() to allow
1262 * loading of the new page_id. It's also called from
1263 * Article::doDeleteArticle()
1264 *
1265 * @param int $newid the new Article ID
1266 * @access public
1267 */
1268 function resetArticleID( $newid ) {
1269 $linkCache =& LinkCache::singleton();
1270 $linkCache->clearBadLink( $this->getPrefixedDBkey() );
1271
1272 if ( 0 == $newid ) { $this->mArticleID = -1; }
1273 else { $this->mArticleID = $newid; }
1274 $this->mRestrictionsLoaded = false;
1275 $this->mRestrictions = array();
1276 }
1277
1278 /**
1279 * Updates page_touched for this page; called from LinksUpdate.php
1280 * @return bool true if the update succeded
1281 * @access public
1282 */
1283 function invalidateCache() {
1284 global $wgUseFileCache;
1285
1286 if ( wfReadOnly() ) {
1287 return;
1288 }
1289
1290 $dbw =& wfGetDB( DB_MASTER );
1291 $success = $dbw->update( 'page',
1292 array( /* SET */
1293 'page_touched' => $dbw->timestamp()
1294 ), array( /* WHERE */
1295 'page_namespace' => $this->getNamespace() ,
1296 'page_title' => $this->getDBkey()
1297 ), 'Title::invalidateCache'
1298 );
1299
1300 if ($wgUseFileCache) {
1301 $cache = new CacheManager($this);
1302 @unlink($cache->fileCacheName());
1303 }
1304
1305 return $success;
1306 }
1307
1308 /**
1309 * Prefix some arbitrary text with the namespace or interwiki prefix
1310 * of this object
1311 *
1312 * @param string $name the text
1313 * @return string the prefixed text
1314 * @access private
1315 */
1316 /* private */ function prefix( $name ) {
1317 global $wgContLang;
1318
1319 $p = '';
1320 if ( '' != $this->mInterwiki ) {
1321 $p = $this->mInterwiki . ':';
1322 }
1323 if ( 0 != $this->mNamespace ) {
1324 $p .= $wgContLang->getNsText( $this->mNamespace ) . ':';
1325 }
1326 return $p . $name;
1327 }
1328
1329 /**
1330 * Secure and split - main initialisation function for this object
1331 *
1332 * Assumes that mDbkeyform has been set, and is urldecoded
1333 * and uses underscores, but not otherwise munged. This function
1334 * removes illegal characters, splits off the interwiki and
1335 * namespace prefixes, sets the other forms, and canonicalizes
1336 * everything.
1337 * @return bool true on success
1338 * @access private
1339 */
1340 /* private */ function secureAndSplit() {
1341 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
1342 $fname = 'Title::secureAndSplit';
1343
1344 # Initialisation
1345 static $rxTc = false;
1346 if( !$rxTc ) {
1347 # % is needed as well
1348 $rxTc = '/[^' . Title::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
1349 }
1350
1351 $this->mInterwiki = $this->mFragment = '';
1352 $this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN
1353
1354 # Clean up whitespace
1355 #
1356 $t = preg_replace( '/[ _]+/', '_', $this->mDbkeyform );
1357 $t = trim( $t, '_' );
1358
1359 if ( '' == $t ) {
1360 return false;
1361 }
1362
1363 if( false !== strpos( $t, UTF8_REPLACEMENT ) ) {
1364 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
1365 return false;
1366 }
1367
1368 $this->mDbkeyform = $t;
1369
1370 # Initial colon indicates main namespace rather than specified default
1371 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
1372 if ( ':' == $t{0} ) {
1373 $this->mNamespace = NS_MAIN;
1374 $t = substr( $t, 1 ); # remove the colon but continue processing
1375 }
1376
1377 # Namespace or interwiki prefix
1378 $firstPass = true;
1379 do {
1380 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) {
1381 $p = $m[1];
1382 $lowerNs = strtolower( $p );
1383 if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
1384 # Canonical namespace
1385 $t = $m[2];
1386 $this->mNamespace = $ns;
1387 } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
1388 # Ordinary namespace
1389 $t = $m[2];
1390 $this->mNamespace = $ns;
1391 } elseif( $this->getInterwikiLink( $p ) ) {
1392 if( !$firstPass ) {
1393 # Can't make a local interwiki link to an interwiki link.
1394 # That's just crazy!
1395 return false;
1396 }
1397
1398 # Interwiki link
1399 $t = $m[2];
1400 $this->mInterwiki = strtolower( $p );
1401
1402 # Redundant interwiki prefix to the local wiki
1403 if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
1404 if( $t == '' ) {
1405 # Can't have an empty self-link
1406 return false;
1407 }
1408 $this->mInterwiki = '';
1409 $firstPass = false;
1410 # Do another namespace split...
1411 continue;
1412 }
1413
1414 # If there's an initial colon after the interwiki, that also
1415 # resets the default namespace
1416 if ( $t !== '' && $t[0] == ':' ) {
1417 $this->mNamespace = NS_MAIN;
1418 $t = substr( $t, 1 );
1419 }
1420 }
1421 # If there's no recognized interwiki or namespace,
1422 # then let the colon expression be part of the title.
1423 }
1424 break;
1425 } while( true );
1426 $r = $t;
1427
1428 # We already know that some pages won't be in the database!
1429 #
1430 if ( '' != $this->mInterwiki || -1 == $this->mNamespace ) {
1431 $this->mArticleID = 0;
1432 }
1433 $f = strstr( $r, '#' );
1434 if ( false !== $f ) {
1435 $this->mFragment = substr( $f, 1 );
1436 $r = substr( $r, 0, strlen( $r ) - strlen( $f ) );
1437 # remove whitespace again: prevents "Foo_bar_#"
1438 # becoming "Foo_bar_"
1439 $r = preg_replace( '/_*$/', '', $r );
1440 }
1441
1442 # Reject illegal characters.
1443 #
1444 if( preg_match( $rxTc, $r ) ) {
1445 return false;
1446 }
1447
1448 /**
1449 * Pages with "/./" or "/../" appearing in the URLs will
1450 * often be unreachable due to the way web browsers deal
1451 * with 'relative' URLs. Forbid them explicitly.
1452 */
1453 if ( strpos( $r, '.' ) !== false &&
1454 ( $r === '.' || $r === '..' ||
1455 strpos( $r, './' ) === 0 ||
1456 strpos( $r, '../' ) === 0 ||
1457 strpos( $r, '/./' ) !== false ||
1458 strpos( $r, '/../' ) !== false ) )
1459 {
1460 return false;
1461 }
1462
1463 # We shouldn't need to query the DB for the size.
1464 #$maxSize = $dbr->textFieldSize( 'page', 'page_title' );
1465 if ( strlen( $r ) > 255 ) {
1466 return false;
1467 }
1468
1469 /**
1470 * Normally, all wiki links are forced to have
1471 * an initial capital letter so [[foo]] and [[Foo]]
1472 * point to the same place.
1473 *
1474 * Don't force it for interwikis, since the other
1475 * site might be case-sensitive.
1476 */
1477 if( $wgCapitalLinks && $this->mInterwiki == '') {
1478 $t = $wgContLang->ucfirst( $r );
1479 } else {
1480 $t = $r;
1481 }
1482
1483 /**
1484 * Can't make a link to a namespace alone...
1485 * "empty" local links can only be self-links
1486 * with a fragment identifier.
1487 */
1488 if( $t == '' &&
1489 $this->mInterwiki == '' &&
1490 $this->mNamespace != NS_MAIN ) {
1491 return false;
1492 }
1493
1494 # Fill fields
1495 $this->mDbkeyform = $t;
1496 $this->mUrlform = wfUrlencode( $t );
1497
1498 $this->mTextform = str_replace( '_', ' ', $t );
1499
1500 return true;
1501 }
1502
1503 /**
1504 * Get a Title object associated with the talk page of this article
1505 * @return Title the object for the talk page
1506 * @access public
1507 */
1508 function getTalkPage() {
1509 return Title::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
1510 }
1511
1512 /**
1513 * Get a title object associated with the subject page of this
1514 * talk page
1515 *
1516 * @return Title the object for the subject page
1517 * @access public
1518 */
1519 function getSubjectPage() {
1520 return Title::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
1521 }
1522
1523 /**
1524 * Get an array of Title objects linking to this Title
1525 * Also stores the IDs in the link cache.
1526 *
1527 * @param string $options may be FOR UPDATE
1528 * @return array the Title objects linking here
1529 * @access public
1530 */
1531 function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
1532 $linkCache =& LinkCache::singleton();
1533 $id = $this->getArticleID();
1534
1535 if ( $options ) {
1536 $db =& wfGetDB( DB_MASTER );
1537 } else {
1538 $db =& wfGetDB( DB_SLAVE );
1539 }
1540
1541 $res = $db->select( array( 'page', $table ),
1542 array( 'page_namespace', 'page_title', 'page_id' ),
1543 array(
1544 "{$prefix}_from=page_id",
1545 "{$prefix}_namespace" => $this->getNamespace(),
1546 "{$prefix}_title" => $this->getDbKey() ),
1547 'Title::getLinksTo',
1548 $options );
1549
1550 $retVal = array();
1551 if ( $db->numRows( $res ) ) {
1552 while ( $row = $db->fetchObject( $res ) ) {
1553 if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
1554 $linkCache->addGoodLinkObj( $row->page_id, $titleObj );
1555 $retVal[] = $titleObj;
1556 }
1557 }
1558 }
1559 $db->freeResult( $res );
1560 return $retVal;
1561 }
1562
1563 /**
1564 * Get an array of Title objects using this Title as a template
1565 * Also stores the IDs in the link cache.
1566 *
1567 * @param string $options may be FOR UPDATE
1568 * @return array the Title objects linking here
1569 * @access public
1570 */
1571 function getTemplateLinksTo( $options = '' ) {
1572 return $this->getLinksTo( $options, 'templatelinks', 'tl' );
1573 }
1574
1575 /**
1576 * Get an array of Title objects referring to non-existent articles linked from this page
1577 *
1578 * @param string $options may be FOR UPDATE
1579 * @return array the Title objects
1580 * @access public
1581 */
1582 function getBrokenLinksFrom( $options = '' ) {
1583 if ( $options ) {
1584 $db =& wfGetDB( DB_MASTER );
1585 } else {
1586 $db =& wfGetDB( DB_SLAVE );
1587 }
1588
1589 $res = $db->safeQuery(
1590 "SELECT pl_namespace, pl_title
1591 FROM !
1592 LEFT JOIN !
1593 ON pl_namespace=page_namespace
1594 AND pl_title=page_title
1595 WHERE pl_from=?
1596 AND page_namespace IS NULL
1597 !",
1598 $db->tableName( 'pagelinks' ),
1599 $db->tableName( 'page' ),
1600 $this->getArticleId(),
1601 $options );
1602
1603 $retVal = array();
1604 if ( $db->numRows( $res ) ) {
1605 while ( $row = $db->fetchObject( $res ) ) {
1606 $retVal[] = Title::makeTitle( $row->pl_namespace, $row->pl_title );
1607 }
1608 }
1609 $db->freeResult( $res );
1610 return $retVal;
1611 }
1612
1613
1614 /**
1615 * Get a list of URLs to purge from the Squid cache when this
1616 * page changes
1617 *
1618 * @return array the URLs
1619 * @access public
1620 */
1621 function getSquidURLs() {
1622 return array(
1623 $this->getInternalURL(),
1624 $this->getInternalURL( 'action=history' )
1625 );
1626 }
1627
1628 /**
1629 * Move this page without authentication
1630 * @param Title &$nt the new page Title
1631 * @access public
1632 */
1633 function moveNoAuth( &$nt ) {
1634 return $this->moveTo( $nt, false );
1635 }
1636
1637 /**
1638 * Check whether a given move operation would be valid.
1639 * Returns true if ok, or a message key string for an error message
1640 * if invalid. (Scarrrrry ugly interface this.)
1641 * @param Title &$nt the new title
1642 * @param bool $auth indicates whether $wgUser's permissions
1643 * should be checked
1644 * @return mixed true on success, message name on failure
1645 * @access public
1646 */
1647 function isValidMoveOperation( &$nt, $auth = true ) {
1648 global $wgUser;
1649 if( !$this or !$nt ) {
1650 return 'badtitletext';
1651 }
1652 if( $this->equals( $nt ) ) {
1653 return 'selfmove';
1654 }
1655 if( !$this->isMovable() || !$nt->isMovable() ) {
1656 return 'immobile_namespace';
1657 }
1658
1659 $oldid = $this->getArticleID();
1660 $newid = $nt->getArticleID();
1661
1662 if ( strlen( $nt->getDBkey() ) < 1 ) {
1663 return 'articleexists';
1664 }
1665 if ( ( '' == $this->getDBkey() ) ||
1666 ( !$oldid ) ||
1667 ( '' == $nt->getDBkey() ) ) {
1668 return 'badarticleerror';
1669 }
1670
1671 if ( $auth && (
1672 !$this->userCanEdit() || !$nt->userCanEdit() ||
1673 !$this->userCanMove() || !$nt->userCanMove() ) ) {
1674 return 'protectedpage';
1675 }
1676
1677 # The move is allowed only if (1) the target doesn't exist, or
1678 # (2) the target is a redirect to the source, and has no history
1679 # (so we can undo bad moves right after they're done).
1680
1681 if ( 0 != $newid ) { # Target exists; check for validity
1682 if ( ! $this->isValidMoveTarget( $nt ) ) {
1683 return 'articleexists';
1684 }
1685 }
1686 return true;
1687 }
1688
1689 /**
1690 * Move a title to a new location
1691 * @param Title &$nt the new title
1692 * @param bool $auth indicates whether $wgUser's permissions
1693 * should be checked
1694 * @return mixed true on success, message name on failure
1695 * @access public
1696 */
1697 function moveTo( &$nt, $auth = true, $reason = '' ) {
1698 $err = $this->isValidMoveOperation( $nt, $auth );
1699 if( is_string( $err ) ) {
1700 return $err;
1701 }
1702
1703 $pageid = $this->getArticleID();
1704 if( $nt->exists() ) {
1705 $this->moveOverExistingRedirect( $nt, $reason );
1706 $pageCountChange = 0;
1707 } else { # Target didn't exist, do normal move.
1708 $this->moveToNewTitle( $nt, $reason );
1709 $pageCountChange = 1;
1710 }
1711 $redirid = $this->getArticleID();
1712
1713 # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
1714 $dbw =& wfGetDB( DB_MASTER );
1715 $categorylinks = $dbw->tableName( 'categorylinks' );
1716 $sql = "UPDATE $categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
1717 " WHERE cl_from=" . $dbw->addQuotes( $pageid ) .
1718 " AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
1719 $dbw->query( $sql, 'SpecialMovepage::doSubmit' );
1720
1721 # Update watchlists
1722
1723 $oldnamespace = $this->getNamespace() & ~1;
1724 $newnamespace = $nt->getNamespace() & ~1;
1725 $oldtitle = $this->getDBkey();
1726 $newtitle = $nt->getDBkey();
1727
1728 if( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) {
1729 WatchedItem::duplicateEntries( $this, $nt );
1730 }
1731
1732 # Update search engine
1733 $u = new SearchUpdate( $pageid, $nt->getPrefixedDBkey() );
1734 $u->doUpdate();
1735 $u = new SearchUpdate( $redirid, $this->getPrefixedDBkey(), '' );
1736 $u->doUpdate();
1737
1738 # Update site_stats
1739 if ( $this->getNamespace() == NS_MAIN and $nt->getNamespace() != NS_MAIN ) {
1740 # Moved out of main namespace
1741 # not viewed, edited, removing
1742 $u = new SiteStatsUpdate( 0, 1, -1, $pageCountChange);
1743 } elseif ( $this->getNamespace() != NS_MAIN and $nt->getNamespace() == NS_MAIN ) {
1744 # Moved into main namespace
1745 # not viewed, edited, adding
1746 $u = new SiteStatsUpdate( 0, 1, +1, $pageCountChange );
1747 } elseif ( $pageCountChange ) {
1748 # Added redirect
1749 $u = new SiteStatsUpdate( 0, 0, 0, 1 );
1750 } else{
1751 $u = false;
1752 }
1753 if ( $u ) {
1754 $u->doUpdate();
1755 }
1756
1757 global $wgUser;
1758 wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
1759 return true;
1760 }
1761
1762 /**
1763 * Move page to a title which is at present a redirect to the
1764 * source page
1765 *
1766 * @param Title &$nt the page to move to, which should currently
1767 * be a redirect
1768 * @access private
1769 */
1770 function moveOverExistingRedirect( &$nt, $reason = '' ) {
1771 global $wgUser, $wgUseSquid, $wgMwRedir;
1772 $fname = 'Title::moveOverExistingRedirect';
1773 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1774
1775 if ( $reason ) {
1776 $comment .= ": $reason";
1777 }
1778
1779 $now = wfTimestampNow();
1780 $rand = wfRandom();
1781 $newid = $nt->getArticleID();
1782 $oldid = $this->getArticleID();
1783 $dbw =& wfGetDB( DB_MASTER );
1784 $linkCache =& LinkCache::singleton();
1785
1786 # Delete the old redirect. We don't save it to history since
1787 # by definition if we've got here it's rather uninteresting.
1788 # We have to remove it so that the next step doesn't trigger
1789 # a conflict on the unique namespace+title index...
1790 $dbw->delete( 'page', array( 'page_id' => $newid ), $fname );
1791
1792 # Save a null revision in the page's history notifying of the move
1793 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
1794 $nullRevId = $nullRevision->insertOn( $dbw );
1795
1796 # Change the name of the target page:
1797 $dbw->update( 'page',
1798 /* SET */ array(
1799 'page_touched' => $dbw->timestamp($now),
1800 'page_namespace' => $nt->getNamespace(),
1801 'page_title' => $nt->getDBkey(),
1802 'page_latest' => $nullRevId,
1803 ),
1804 /* WHERE */ array( 'page_id' => $oldid ),
1805 $fname
1806 );
1807 $linkCache->clearLink( $nt->getPrefixedDBkey() );
1808
1809 # Recreate the redirect, this time in the other direction.
1810 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
1811 $redirectArticle = new Article( $this );
1812 $newid = $redirectArticle->insertOn( $dbw );
1813 $redirectRevision = new Revision( array(
1814 'page' => $newid,
1815 'comment' => $comment,
1816 'text' => $redirectText ) );
1817 $revid = $redirectRevision->insertOn( $dbw );
1818 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
1819 $linkCache->clearLink( $this->getPrefixedDBkey() );
1820
1821 # Log the move
1822 $log = new LogPage( 'move' );
1823 $log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText() ) );
1824
1825 # Now, we record the link from the redirect to the new title.
1826 # It should have no other outgoing links...
1827 $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), $fname );
1828 $dbw->insert( 'pagelinks',
1829 array(
1830 'pl_from' => $newid,
1831 'pl_namespace' => $nt->getNamespace(),
1832 'pl_title' => $nt->getDbKey() ),
1833 $fname );
1834
1835 # Purge squid
1836 if ( $wgUseSquid ) {
1837 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
1838 $u = new SquidUpdate( $urls );
1839 $u->doUpdate();
1840 }
1841 }
1842
1843 /**
1844 * Move page to non-existing title.
1845 * @param Title &$nt the new Title
1846 * @access private
1847 */
1848 function moveToNewTitle( &$nt, $reason = '' ) {
1849 global $wgUser, $wgUseSquid;
1850 global $wgMwRedir;
1851 $fname = 'MovePageForm::moveToNewTitle';
1852 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1853 if ( $reason ) {
1854 $comment .= ": $reason";
1855 }
1856
1857 $newid = $nt->getArticleID();
1858 $oldid = $this->getArticleID();
1859 $dbw =& wfGetDB( DB_MASTER );
1860 $now = $dbw->timestamp();
1861 $rand = wfRandom();
1862 $linkCache =& LinkCache::singleton();
1863
1864 # Save a null revision in the page's history notifying of the move
1865 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
1866 $nullRevId = $nullRevision->insertOn( $dbw );
1867
1868 # Rename cur entry
1869 $dbw->update( 'page',
1870 /* SET */ array(
1871 'page_touched' => $now,
1872 'page_namespace' => $nt->getNamespace(),
1873 'page_title' => $nt->getDBkey(),
1874 'page_latest' => $nullRevId,
1875 ),
1876 /* WHERE */ array( 'page_id' => $oldid ),
1877 $fname
1878 );
1879
1880 $linkCache->clearLink( $nt->getPrefixedDBkey() );
1881
1882 # Insert redirect
1883 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
1884 $redirectArticle = new Article( $this );
1885 $newid = $redirectArticle->insertOn( $dbw );
1886 $redirectRevision = new Revision( array(
1887 'page' => $newid,
1888 'comment' => $comment,
1889 'text' => $redirectText ) );
1890 $revid = $redirectRevision->insertOn( $dbw );
1891 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
1892 $linkCache->clearLink( $this->getPrefixedDBkey() );
1893
1894 # Log the move
1895 $log = new LogPage( 'move' );
1896 $log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText()) );
1897
1898 # Purge caches as per article creation
1899 Article::onArticleCreate( $nt );
1900
1901 # Record the just-created redirect's linking to the page
1902 $dbw->insert( 'pagelinks',
1903 array(
1904 'pl_from' => $newid,
1905 'pl_namespace' => $nt->getNamespace(),
1906 'pl_title' => $nt->getDBkey() ),
1907 $fname );
1908
1909 # Non-existent target may have had broken links to it; these must
1910 # now be touched to update link coloring.
1911 $nt->touchLinks();
1912
1913 # Purge old title from squid
1914 # The new title, and links to the new title, are purged in Article::onArticleCreate()
1915 $titles = $nt->getLinksTo();
1916 if ( $wgUseSquid ) {
1917 $urls = $this->getSquidURLs();
1918 foreach ( $titles as $linkTitle ) {
1919 $urls[] = $linkTitle->getInternalURL();
1920 }
1921 $u = new SquidUpdate( $urls );
1922 $u->doUpdate();
1923 }
1924 }
1925
1926 /**
1927 * Checks if $this can be moved to a given Title
1928 * - Selects for update, so don't call it unless you mean business
1929 *
1930 * @param Title &$nt the new title to check
1931 * @access public
1932 */
1933 function isValidMoveTarget( $nt ) {
1934
1935 $fname = 'Title::isValidMoveTarget';
1936 $dbw =& wfGetDB( DB_MASTER );
1937
1938 # Is it a redirect?
1939 $id = $nt->getArticleID();
1940 $obj = $dbw->selectRow( array( 'page', 'revision', 'text'),
1941 array( 'page_is_redirect','old_text','old_flags' ),
1942 array( 'page_id' => $id, 'page_latest=rev_id', 'rev_text_id=old_id' ),
1943 $fname, 'FOR UPDATE' );
1944
1945 if ( !$obj || 0 == $obj->page_is_redirect ) {
1946 # Not a redirect
1947 return false;
1948 }
1949 $text = Revision::getRevisionText( $obj );
1950
1951 # Does the redirect point to the source?
1952 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $text, $m ) ) {
1953 $redirTitle = Title::newFromText( $m[1] );
1954 if( !is_object( $redirTitle ) ||
1955 $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() ) {
1956 return false;
1957 }
1958 } else {
1959 # Fail safe
1960 return false;
1961 }
1962
1963 # Does the article have a history?
1964 $row = $dbw->selectRow( array( 'page', 'revision'),
1965 array( 'rev_id' ),
1966 array( 'page_namespace' => $nt->getNamespace(),
1967 'page_title' => $nt->getDBkey(),
1968 'page_id=rev_page AND page_latest != rev_id'
1969 ), $fname, 'FOR UPDATE'
1970 );
1971
1972 # Return true if there was no history
1973 return $row === false;
1974 }
1975
1976 /**
1977 * Create a redirect; fails if the title already exists; does
1978 * not notify RC
1979 *
1980 * @param Title $dest the destination of the redirect
1981 * @param string $comment the comment string describing the move
1982 * @return bool true on success
1983 * @access public
1984 */
1985 function createRedirect( $dest, $comment ) {
1986 global $wgUser;
1987 if ( $this->getArticleID() ) {
1988 return false;
1989 }
1990
1991 $fname = 'Title::createRedirect';
1992 $dbw =& wfGetDB( DB_MASTER );
1993
1994 $article = new Article( $this );
1995 $newid = $article->insertOn( $dbw );
1996 $revision = new Revision( array(
1997 'page' => $newid,
1998 'comment' => $comment,
1999 'text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n",
2000 ) );
2001 $revisionId = $revision->insertOn( $dbw );
2002 $article->updateRevisionOn( $dbw, $revision, 0 );
2003
2004 # Link table
2005 $dbw->insert( 'pagelinks',
2006 array(
2007 'pl_from' => $newid,
2008 'pl_namespace' => $dest->getNamespace(),
2009 'pl_title' => $dest->getDbKey()
2010 ), $fname
2011 );
2012
2013 Article::onArticleCreate( $this );
2014 return true;
2015 }
2016
2017 /**
2018 * Get categories to which this Title belongs and return an array of
2019 * categories' names.
2020 *
2021 * @return array an array of parents in the form:
2022 * $parent => $currentarticle
2023 * @access public
2024 */
2025 function getParentCategories() {
2026 global $wgContLang,$wgUser;
2027
2028 $titlekey = $this->getArticleId();
2029 $dbr =& wfGetDB( DB_SLAVE );
2030 $categorylinks = $dbr->tableName( 'categorylinks' );
2031
2032 # NEW SQL
2033 $sql = "SELECT * FROM $categorylinks"
2034 ." WHERE cl_from='$titlekey'"
2035 ." AND cl_from <> '0'"
2036 ." ORDER BY cl_sortkey";
2037
2038 $res = $dbr->query ( $sql ) ;
2039
2040 if($dbr->numRows($res) > 0) {
2041 while ( $x = $dbr->fetchObject ( $res ) )
2042 //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
2043 $data[$wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to] = $this->getFullText();
2044 $dbr->freeResult ( $res ) ;
2045 } else {
2046 $data = '';
2047 }
2048 return $data;
2049 }
2050
2051 /**
2052 * Get a tree of parent categories
2053 * @param array $children an array with the children in the keys, to check for circular refs
2054 * @return array
2055 * @access public
2056 */
2057 function getParentCategoryTree( $children = array() ) {
2058 $parents = $this->getParentCategories();
2059
2060 if($parents != '') {
2061 foreach($parents as $parent => $current) {
2062 if ( array_key_exists( $parent, $children ) ) {
2063 # Circular reference
2064 $stack[$parent] = array();
2065 } else {
2066 $nt = Title::newFromText($parent);
2067 $stack[$parent] = $nt->getParentCategoryTree( $children + array($parent => 1) );
2068 }
2069 }
2070 return $stack;
2071 } else {
2072 return array();
2073 }
2074 }
2075
2076
2077 /**
2078 * Get an associative array for selecting this title from
2079 * the "page" table
2080 *
2081 * @return array
2082 * @access public
2083 */
2084 function pageCond() {
2085 return array( 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform );
2086 }
2087
2088 /**
2089 * Get the revision ID of the previous revision
2090 *
2091 * @param integer $revision Revision ID. Get the revision that was before this one.
2092 * @return interger $oldrevision|false
2093 */
2094 function getPreviousRevisionID( $revision ) {
2095 $dbr =& wfGetDB( DB_SLAVE );
2096 return $dbr->selectField( 'revision', 'rev_id',
2097 'rev_page=' . intval( $this->getArticleId() ) .
2098 ' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );
2099 }
2100
2101 /**
2102 * Get the revision ID of the next revision
2103 *
2104 * @param integer $revision Revision ID. Get the revision that was after this one.
2105 * @return interger $oldrevision|false
2106 */
2107 function getNextRevisionID( $revision ) {
2108 $dbr =& wfGetDB( DB_SLAVE );
2109 return $dbr->selectField( 'revision', 'rev_id',
2110 'rev_page=' . intval( $this->getArticleId() ) .
2111 ' AND rev_id>' . intval( $revision ) . ' ORDER BY rev_id' );
2112 }
2113
2114 /**
2115 * Compare with another title.
2116 *
2117 * @param Title $title
2118 * @return bool
2119 */
2120 function equals( $title ) {
2121 // Note: === is necessary for proper matching of number-like titles.
2122 return $this->getInterwiki() === $title->getInterwiki()
2123 && $this->getNamespace() == $title->getNamespace()
2124 && $this->getDbkey() === $title->getDbkey();
2125 }
2126
2127 /**
2128 * Check if page exists
2129 * @return bool
2130 */
2131 function exists() {
2132 return $this->getArticleId() != 0;
2133 }
2134
2135 /**
2136 * Should a link should be displayed as a known link, just based on its title?
2137 *
2138 * Currently, a self-link with a fragment and special pages are in
2139 * this category. Special pages never exist in the database.
2140 */
2141 function isAlwaysKnown() {
2142 return $this->isExternal() || ( 0 == $this->mNamespace && "" == $this->mDbkeyform )
2143 || NS_SPECIAL == $this->mNamespace;
2144 }
2145
2146 /**
2147 * Update page_touched timestamps on pages linking to this title.
2148 * In principal, this could be backgrounded and could also do squid
2149 * purging.
2150 */
2151 function touchLinks() {
2152 $fname = 'Title::touchLinks';
2153
2154 $dbw =& wfGetDB( DB_MASTER );
2155
2156 $res = $dbw->select( 'pagelinks',
2157 array( 'pl_from' ),
2158 array(
2159 'pl_namespace' => $this->getNamespace(),
2160 'pl_title' => $this->getDbKey() ),
2161 $fname );
2162
2163 $toucharr = array();
2164 while( $row = $dbw->fetchObject( $res ) ) {
2165 $toucharr[] = $row->pl_from;
2166 }
2167 $dbw->freeResult( $res );
2168
2169 if( $this->getNamespace() == NS_CATEGORY ) {
2170 // Categories show up in a separate set of links as well
2171 $res = $dbw->select( 'categorylinks',
2172 array( 'cl_from' ),
2173 array( 'cl_to' => $this->getDbKey() ),
2174 $fname );
2175 while( $row = $dbw->fetchObject( $res ) ) {
2176 $toucharr[] = $row->cl_from;
2177 }
2178 $dbw->freeResult( $res );
2179 }
2180
2181 if (!count($toucharr))
2182 return;
2183 $dbw->update( 'page', /* SET */ array( 'page_touched' => $dbw->timestamp() ),
2184 /* WHERE */ array( 'page_id' => $toucharr ),$fname);
2185 }
2186
2187 function trackbackURL() {
2188 global $wgTitle, $wgScriptPath, $wgServer;
2189
2190 return "$wgServer$wgScriptPath/trackback.php?article="
2191 . htmlspecialchars(urlencode($wgTitle->getPrefixedDBkey()));
2192 }
2193
2194 function trackbackRDF() {
2195 $url = htmlspecialchars($this->getFullURL());
2196 $title = htmlspecialchars($this->getText());
2197 $tburl = $this->trackbackURL();
2198
2199 return "
2200 <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
2201 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
2202 xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
2203 <rdf:Description
2204 rdf:about=\"$url\"
2205 dc:identifier=\"$url\"
2206 dc:title=\"$title\"
2207 trackback:ping=\"$tburl\" />
2208 </rdf:RDF>";
2209 }
2210 }
2211 ?>